import 'package:flutter/material.dart';
import '../app_state/bloc_provider.dart';

const _textStyle = TextStyle(
  fontSize: 18,
  //color: Colors.indigo,
);

class InfoScreen extends StatefulWidget {
  @override
  _InfoScreenState createState() => _InfoScreenState();
}

class _InfoScreenState extends State<InfoScreen> {
  static BlocProvider blocProvider;

  @override
  void initState() {
    super.initState();
    blocProvider = BlocProvider.instance;
  }

  static int allTasks = 0;
  static int tasksDone = 0;

  Widget buildBody() {
    return StreamBuilder<Map<String, int>>(
        initialData: {'allTodos': 0, 'doneTodos': 0},
        stream: BlocProvider.statsStream,
        builder: (context, snapshot) {
          return Container(
            padding: const EdgeInsets.all(20),
            child: Stack(
              children: <Widget>[
                Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  mainAxisSize: MainAxisSize.min,
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: <Widget>[
                    Center(
                      child: Image.asset('assets/app_icon.png',
                          width: 64, height: 64),
                    ),
                    SizedBox(
                      height: 40,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Text(
                          '所有事情',
                          style: _textStyle,
                        ),
                        Text(
                          snapshot.data['allTodos'].toString(),
                          style:
                              TextStyle(fontSize: 22, color: Colors.red[300]),
                        ),
                      ],
                    ),
                    SizedBox(
                      height: 30,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Text(
                          '已做完',
                          style: _textStyle,
                        ),
                        Text(
                          snapshot.data['doneTodos'].toString(),
                          style:
                              TextStyle(fontSize: 22, color: Colors.red[300]),
                        ),
                      ],
                    ),
                    SizedBox(
                      height: 40,
                    ),
                    Center(
                      child: Text(
                        (snapshot.data['doneTodos'] / snapshot.data['allTodos'])
                                        .isNaN ==
                                    true ||
                                (snapshot.data['doneTodos'] /
                                            snapshot.data['allTodos'])
                                        .isInfinite ==
                                    true
                            ? ''
                            : "完成率: ${(snapshot.data['doneTodos'] / snapshot.data['allTodos'] * 100).truncate()}%",
                        style: TextStyle(
                          fontSize: _textStyle.fontSize,
                          color: Colors.red[300],
                        ),
                      ),
                    ),
                    SizedBox(
                      height: 20,
                    ),
                    Center(
                      child: (snapshot.data['doneTodos'] /
                                  snapshot.data['allTodos'] *
                                  100) ==
                              100
                          ? Icon(
                              Icons.done_all,
                              size: 50,
                              color: Colors.red[300],
                            )
                          : SizedBox(
                              width: 100,
                              height: 100,
                              child: Align(
                                alignment: Alignment.bottomCenter,
                                child: Image.asset(
                                  'assets/calc.png',
                                  color: Colors.grey,
                                  colorBlendMode: BlendMode.modulate,
                                ),
                              ),
                            ),
                    ),
                  ],
                ),
              ],
            ),
          );
        });
  }

  @override
  Widget build(BuildContext context) {
    return buildBody();
  }
}
